"""
MCP主应用程序
"""

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .routes import router

def create_app():
    """创建FastAPI应用"""
    
    # 创建应用
    app = FastAPI(title="Agent-MCP", version="1.0.0")
    
    # 包含路由
    app.include_router(router)
    
    # 添加CORS中间件
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],  # 生产环境应该限制具体域名
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )

    
    return app


if __name__ == "__main__":
    import uvicorn
    import sys
    import argparse

    parser = argparse.ArgumentParser(description="Agent-MCP FastAPI Server")
    parser.add_argument('--host', type=str, default='127.0.0.1', help='Host to bind')
    parser.add_argument('--port', type=int, default=8085, help='Port to bind')
    parser.add_argument('--debug', action='store_true', help='Enable debug log level')
    args = parser.parse_args()

    uvicorn.run(
        "agent_mcp.APP.main_app:create_app",
        host=args.host,
        port=args.port,
        log_level="debug" if args.debug else "info",
        factory=True
    )

